package la.iok.hzsvn.lewin.movie.cloud.controller;

import la.iok.hzsvn.lewin.movie.cloud.service.OrgUnitService;
import la.iok.hzsvn.lewin.movie.core.model.SimpleOrgUnitVo;
import la.iok.hzsvn.share.response.ListDataResponse;
import la.iok.hzsvn.share.response.SingleDataResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("internal-api/orgUnits")
public class OrgUnitInternalController {
    private final OrgUnitService orgUnitService;

    public OrgUnitInternalController(OrgUnitService orgUnitService) {
        this.orgUnitService = orgUnitService;
    }

    @GetMapping("{parent}/childrenIds")
    public ListDataResponse<Long> children(@PathVariable Long parent){
        return new ListDataResponse<>(orgUnitService.childOrgUnitIds(parent));
    }

    @GetMapping("{id}")
    public SingleDataResponse<SimpleOrgUnitVo> orgUnitInfo(@PathVariable Long id){
        SimpleOrgUnitVo orgUnit = orgUnitService.simple(id);
        return new SingleDataResponse<>(orgUnit);
    }

    @GetMapping
    public ListDataResponse<SimpleOrgUnitVo> orgUnits(Long[] ids){
        return new ListDataResponse<>(orgUnitService.simple(ids));
    }

    /**
     * 查找指定加盟商的所有店铺
     * @param ids 加盟商id列表
     * @return 所有店铺id列表,如果ids为空则返回空
     */
    @GetMapping("childrenIds")
    public ListDataResponse<Long> children(Long[] ids){
        return new ListDataResponse<>(orgUnitService.childOrgUnitIds(ids));
    }
}
